import Vue from "vue";
import dayjs from "dayjs";
/* 歌曲时长的过滤器 */
Vue.filter("timeFormat", function (time) {
  if (typeof time === "undefined") return 0;
  let minutes = parseInt(time / 60); // 获取时长分钟
  let seconds = parseInt(time % 60); // 获取时长秒数
  seconds = seconds < 10 ? "0" + seconds : seconds; // 秒
  minutes = minutes < 10 ? "0" + minutes : minutes;
  return minutes + ":" + seconds;
});

/* 时间的过滤器 */
Vue.filter("dateFormat", function (time) {
  if (typeof time === "undefined") return 0;
  return dayjs(time).format("YYYY-MM-DD");
});
/* 播放数量的过滤器 */
Vue.filter("countFormat", function (count) {
  if (typeof count === "undefined" || count === null) return 0;
  if (count < 10000) return count;
  else return Math.floor(count / 10000) + "万";
});
Vue.filter("mvTopFormat", function (index) {
  if (typeof index === "undefined") return;
  return index < 10 ? "0" + index : index;
});
